<?php
/* --------------------------------------------------------------
   callback_service.php 2009-11-18 mb
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2009 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/
?><?php

if(defined('_GM_VALID_CALL') === false) die('x0');

require_once (DIR_FS_INC.'xtc_validate_email.inc.php');
require_once (DIR_FS_INC.'xtc_random_charcode.inc.php');

$session_vvcode = $_SESSION['vvcode'];


// create smarty elements
$smarty = new Smarty;


if($_GET['check'] == '1'){
	$errors = '';
	
	// name and telephone number exist?
	if(empty($_GET['name']) || empty($_GET['telephone'])){
		$errors .= GM_CALLBACK_SERVICE_ERROR . '<br /><br />';
	}
	
	// vvcode check
	if(strtoupper($_GET['vvcode']) != $_SESSION['vvcode'] && gm_get_conf('GM_CALLBACK_SERVICE_VVCODE') == 'true'){
		$errors .= GM_CALLBACK_SERVICE_WRONG_CODE . '<br /><br />';
	}
	
	$visual_verify_code = xtc_random_charcode(6);
	$_SESSION['vvcode'] = $visual_verify_code;
	
	echo $errors;
}
elseif(!empty($_POST['telephone'])){
	
	$message = str_replace('%u20AC', 'EUR', $_POST['message']);
	$message = gm_prepare_string($message);
	$text = GM_CALLBACK_SERVICE_MAIL_NAME . $_POST['name']
				. "\n". GM_CALLBACK_SERVICE_MAIL_EMAIL . $_POST['email']
				. "\n" . GM_CALLBACK_SERVICE_MAIL_TELEPHONE . $_POST['telephone']
				. "\n" . GM_CALLBACK_SERVICE_MAIL_TIME . $_POST['time']
				. "\n\n" . GM_CALLBACK_SERVICE_MAIL_MESSAGE . "\n" . $message;			
					
	if(!empty($_POST['email'])) $email = $_POST['email'];
	else $email = STORE_OWNER_EMAIL_ADDRESS;
	
	// send mail
	xtc_php_mail(CONTACT_US_EMAIL_ADDRESS, CONTACT_US_NAME, CONTACT_US_EMAIL_ADDRESS, CONTACT_US_NAME, '', $email, $_POST['name'], '', '', GM_CALLBACK_SERVICE_SUBJECT . $_POST['name'] . ', ' . $_POST['telephone'], nl2br(htmlentities($text)), html_entity_decode($text));	

	echo GM_CALLBACK_SERVICE_SUCCESS;
}

?>